package com.cryptoneedle.garden.entity.garden.doris;

import com.cryptoneedle.garden.key.TableKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;

/**
 * <p>description: Doris-元数据-TableStatus </p>
 * <p>
 * 数据来源：SHOW TABLE STATUS FROM internal.xxx;
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "doris_table_script")
@IdClass(TableKey.class)
@Comment("Doris-表创建语句")
public class DorisTableScript implements Serializable {

    @Id
    @Column(length = 512)
    @Comment("所属 SourceCatalog")
    private String catalogName;

    @Id
    @Column(length = 64)
    @Comment("所属 SourceDatabase")
    private String databaseName;

    @Id
    @Column(length = 64)
    @Comment("表名称")
    private String tableName;

    @Comment("建表语句")
    private String script;

    public String getKey() {
        return new TableKey(this.catalogName, this.databaseName, this.tableName).toString();
    }
}